<template>
<Modal v-model="modalEdit" fullscreen @on-ok="handleModalEditOK" 
@on-cancel="handleModalEditCancel"  ok-text="提交">
<template #header>
		<Icon custom="iconfont icon-Word"/>&nbsp;现场勘验（检查）笔录&nbsp;
</template>
<div><Row justify="center"><Col span="20">
	<Card title="基本信息" icon="ios-bookmark">
		<template #extra>
			{{baseform.party_name}}&nbsp;涉嫌&nbsp;{{baseform.cause_name}}
		</template>
		<Row>
		    <Col span="10"><Space>
				<span>*时间：</span>
				<DatePicker v-model="baseform.date" type="date" placeholder="选择日期" style="width: 128px" />
				<TimePicker v-model="baseform.time" format="HH:mm" type="timerange" 
				placement="bottom-end" placeholder="选择时间" style="width: 200px" /> 
			</Space></Col>
			<Col span="14"><Space>
				<span>*勘验（检查）人：</span>
				<Select v-model="baseform.legal1"  filterable>
					<Option v-for="n in optionsLegal" :value="n.uid"  :key="n.uid">
						<span>{{ n.uname }}</span>
						<span style="float: right;color: #999;">{{ n.uid }}</span>
					</Option>
				</Select>
				<Select v-model="baseform.legal2"  filterable>
					<Option v-for="n in optionsLegal" :value="n.uid"  :key="n.uid">
						<span>{{ n.uname }}</span>
						<span style="float: right;color: #999;">{{ n.uid }}</span>
					</Option>
				</Select>
			</Space></Col>
		</Row><br>
		<Row>
			<Col span="10"><Space>
				<span>*地点：</span>
				<Input v-model="baseform.location" placeholder="输入地点" style="width: 320px;"/>
			</Space></Col>
			<Col span="14"><Space>
				<span>*记录人：</span>
				<Select v-model="baseform.legal3"  filterable>
					<Option v-for="n in optionsLegal" :value="n.uid"  :key="n.uid">
						<span>{{ n.uname }}</span>
						<span style="float: right;color: #999;">{{ n.uid }}</span>
					</Option>
				</Select>
			</Space></Col>
		</Row><br>
		<Row>
			<Col span="24"><Space>
			<span>&nbsp;天气：</span>
			<Input v-model="baseform.weather" placeholder="输入天气"/>
			</Space></Col>
		</Row>
		<!--
		<Divider/>
		<Row><Col span="24"><Space>
			<RadioGroup v-model="baseform.party_type" type="button" button-style="solid">
				<Radio label="个人" v-width="100"></Radio>
				<Radio label="法人" v-width="100"></Radio>
			</RadioGroup>
		</Space></Col></Row><br>
		<Row v-if="baseform.party_type==='个人'">
			<Col span="10"><Space>
				<span>*被勘验（检查）人姓名：</span>
				<AutoComplete v-model="baseform.person_name"  @on-search="handleSearchPerson"
				@on-change="handlePersonChange">
					<Option v-for="n in optionsPerson" :value="n.person_name" 
					:key="n.person_id" @click="handleReloadData(n)">
						<span>{{ n.person_name }}</span>
						<span style="float: right;color: #999;">{{ n.person_id }}</span>
					</Option>
				</AutoComplete>
				<Button shape="circle" icon="md-add" @click="handleAddPerson"></Button>
			</Space></Col>
			<Col span="14"><Space>
				*身份证号：<Input v-model="baseform.person_id" disabled/>
			</Space></Col>
		</Row>
		<Row v-if="baseform.party_type==='法人'">
			<Col span="10"><Space>
				<span>*被勘验（检查）名称：</span>
				<AutoComplete v-model="baseform.enterprise_name" @on-search="handleSearchEnterprise"
				@on-change="handleEnterpriseChange">
				    <Option v-for="(n, i) in optionsEnterprise" :value="n.enterprise_name" 
					:key="i" @click="handleReloadData(n)">{{n.enterprise_name}}</Option>
				</AutoComplete>
				<Button shape="circle" icon="md-add" @click="handleAddEnterprise"></Button>
			</Space></Col>
			<Col span="14"><Space>
				*统一社会信用代码：<Input v-model="baseform.reg_num" disabled/>
			</Space></Col>
		</Row>
		-->
	</Card>
	<br>
	<Card title="勘验（检查）记录" icon="ios-bookmark">
		<Input v-model="baseform.record" type="textarea" :autosize="{minRows: 2,maxRows: 50}" placeholder="Enter something..." />
	</Card>
</Col></Row></div>
<AddPerson ref="addPerson" @loadData="handleReloadData"></AddPerson>
<AddEnterprise ref="addEnterprise" @loadData="handleReloadData"></AddEnterprise>
</Modal>
</template>

<script>
import {dateUtils,appendDoc} from '@/libs/tools.js'
import config from '@/config'
import AddPerson from '@/components/AddPerson'
import AddEnterprise from '@/components/AddEnterprise'
export default{
	data(){
		return {
			modalEdit:true,
			optionsLegal:[],
			optionsEnterprise:[],
			optionsPerson:[],
			baseform:{party_type:'法人'}		
		}
	},
	components: {
		AddEnterprise,AddPerson
    },
	methods:{
		handleModalEditCancel(){
			this.$router.go(-1)
		},
		handleModalEditOK(){
			let data={...this.baseform}
			data.time1=data.time[0]
			data.time2=data.time[1]
			data.date1=dateUtils.format2(data.date)
			data.docs=appendDoc(data.docs,"doc104")
			console.info(this.baseform)
			this.$axios.post('mainCase1CreateDoc104.action',data).then(res=>{
				window.open(config.baseUrl+res.data,'_blank')
			})
			this.$router.go(-1)
		},
		/*
		handleSearchPerson(k){
			this.$axios.post("mainCase1PersonSelect.action",{int1:0,str1:k})
			.then(res=>{
				this.optionsPerson=res.data.slice(0,5)
			})
		},
		handlePersonChange(value){
			if(value=='')this.optionsPerson=[]
		},
		handleSearchEnterprise(k){
			this.$axios.post("mainCase1EnterpriseSelect.action",{int1:0,str1:k})
			.then(res=>{
				this.optionsEnterprise=res.data.slice(0,5)
			})
		},
		handleEnterpriseChange(value){
			if(value=='')this.optionsEnterprise=[]
		},
		handleAddPerson(){
			this.$refs.addPerson.open()
		},
		handleAddEnterprise(){
			this.$refs.addEnterprise.open()
		},*/
		handleReloadData(data){
			this.baseform={...this.baseform,...data}
		}
		
	},
	mounted(){
		this.$axios.post("mainCase1GetDoc103Legals.action",{str1:''})
		.then(res=>{
			this.optionsLegal=res.data
		})
		this.$axios.post('mainCase1GetDoc104.action',{
			case_no:this.$route.query.case_no,
			party_type:this.$route.query.party_type
		}).then(res=>{
			this.baseform={...this.baseform,...res.data}
			if(this.baseform.time1!=null){
				this.baseform.time=new Array(2)
				this.baseform.time[0]=this.baseform.time1
				this.baseform.time[1]=this.baseform.time2
			}
			if(this.baseform.record==null){
				this.baseform.record=''
			}
			if(this.baseform.date1==null){
				this.baseform.date=new Date()
			}else{
				this.baseform.date=this.$Date(this.baseform.date1,'YYYY-MM-DD').toDate()
			}
		})
	}
}
</script>

<style>
</style>